<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2018/12/21
 * Time: 10:08
 */

namespace app\admin\controller;


use think\Db;

class Inout extends Base
{
    /**
     * 收入
     * @return mixed|\think\response\Json
     */
    public function income(){
        if(request()->isAjax ()){
            $params = input('param.');
            $where['ji_type'] = 1;
            $where['ji_status'] = 2;
            //记录编号
            if(isset($params['ji_num']) && $params['ji_num'] != ''){
                $where['ji_num'] = ['like', "%" . $params['ji_num'] . "%"];
            }
            //记录名称
            if(isset($params['ji_title']) && $params['ji_title'] != ''){
                $where['ji_title'] = ['like', "%" . $params['ji_title'] . "%"];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('jilu')
                ->join('up_u_user', 'user_id = ji_user_id', 'left')
                ->where($where)
                ->count();;//计算总页面
            $lists = Db::name('jilu')
                ->join('up_u_user', 'user_id = ji_user_id', 'left')
                ->where($where)
                ->order('ji_id desc')
                ->field('ji_id, ji_num, ji_title, ji_from, ji_money, ji_time, user_username, user_type')
                ->page($Nowpage, $limits)
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch('inout/income');
    }
    
    /**
     * 支出
     * @return mixed|\think\response\Json
     */
    public function expend(){
        if(request()->isAjax ()){
            $params = input('param.');
            $where['ji_type'] = 2;
            $where['ji_status'] = 2;
            //记录编号
            if(isset($params['ji_num']) && $params['ji_num'] != ''){
                $where['ji_num'] = ['like', "%" . $params['ji_num'] . "%"];
            }
            //记录名称
            if(isset($params['ji_title']) && $params['ji_title'] != ''){
                $where['ji_title'] = ['like', "%" . $params['ji_title'] . "%"];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('jilu')
                ->join('up_u_user', 'user_id = ji_user_id', 'left')
                ->where($where)
                ->count();
            $lists = Db::name('jilu')
                ->join('up_u_user', 'user_id = ji_user_id', 'left')
                ->where($where)
                ->order('ji_id desc')
                ->field('ji_id, ji_num, ji_title, ji_from, ji_money, ji_time, user_username, user_type')
                ->page($Nowpage, $limits)
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch('inout/expend');
    }
}